package Review;

public class Test03 {

	public static void main(String[] args) {
		int[][] matrix = {{0,3,6},{1,4,7},{2,5,8}};
		System.out.println(hasNumber(matrix,6));

	}
    public static boolean hasNumber(int[][]matrix,int number){
    	if(matrix==null||matrix.length==0||matrix[0].length==0)
    	   return false;
    	int rows =matrix.length;
    	int columns = matrix[0].length;
    	int i = 0;
    	int j = columns-1;
    	while(i<rows&&j>=0){
    		if(matrix[i][j]==number){
    			return true;
    		}
    		else if(matrix[i][j]>number){
    			j--;
    		}
    		else{
    			i++;
    		}
    	}
    	return false;
    }
}
